import { contextBridge } from 'electron'
import { electronAPI } from '@electron-toolkit/preload'
import baseApi from './modules/baseApi'
import fsApi from './modules/fsApi'
import taskApi from './modules/taskApi'

// 如果启用了 contextIsolation（安全模式）
if (process.contextIsolated) {
  try {
    contextBridge.exposeInMainWorld('electron', electronAPI)
    contextBridge.exposeInMainWorld('baseApi', baseApi)
    contextBridge.exposeInMainWorld('taskApi', taskApi)
    contextBridge.exposeInMainWorld('fsApi', fsApi)
  } catch (error) {
    console.error(error)
  }
} else {
  // @ts-ignore (define in dts)
  window.electron = electronAPI
  // @ts-ignore (define in dts)
  window.baseApi = baseApi
  // @ts-ignore (define in dts)
  window.taskApi = taskApi
  // @ts-ignore (define in dts)
  window.fsApi = fsApi
}
